package com.arthur.controller;

import com.arthur.bean.User;
import com.arthur.service.UserService;
import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UpdateProductController {
    @Autowired
    @Qualifier("userService")
    private UserService userService;
    @RequestMapping("/UpdateProductController")
    @ResponseBody
    protected Map UpdateProductInfo(HttpServletRequest request, HttpServletResponse response)throws Exception{
        Map<String, Object> objectMap = new HashMap<>();
        response.setCharacterEncoding("UTF-8");
        String username=request.getParameter("username");
        String userpwd=request.getParameter("userpwd");
        String nickname=request.getParameter("nickname");
        int phonenum=Integer.parseInt(request.getParameter("phonenum"));
        String deliveryaddress=request.getParameter("deliveryaddress");
        User userinfo=new User();
        userinfo.setUsername(username);
        userinfo.setUserpwd(userpwd);
        userinfo.setNickname(nickname);
        userinfo.setPhonenum(phonenum);
        userinfo.setDeliveryaddress(deliveryaddress);
        System.out.println(phonenum);
        int rows=userService.updateUser(userinfo);
        if(rows==1){
            objectMap.put("result","1");
        }else {
            objectMap.put("result","0");
        }
        return objectMap;
    }
}
